<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    dialog-width="600px"
    :page-show="pageShow"
    @dialog-close="dialogClose"
  >
    <template #toolPanel />
    <template #searchPanel>
      <search-panel :show-add-button="false" :show-search-button="true"
                    labelWidth="73" @search="search" :left="true">
        <el-form-item label="供货商:" prop="useruuid">
          <el-select v-model="filters.useruuid" filterable collapse-tags clearable placeholder="请选择供货商"  >
            <el-option value="0" label="全部">全部</el-option>
            <el-option
              v-for="item in users"
              :key="item.user.useruuid"
              :label="item.user.username"
              :value="item.user.useruuid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间:">
          <el-date-picker type="date" placeholder="开始时间"  clearable format="yyyy-MM-dd"   v-model="filters.starttime" style="width: 100%;"></el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间:">
          <el-date-picker type="date" placeholder="结束时间" clearable format="yyyy-MM-dd"   v-model="filters.endtime" style="width: 100%;"></el-date-picker>
        </el-form-item>
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="false"
        :current="start"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <template #action="{row}">
        </template>
      </data-table>
    </template>

    <template #dialog>
    </template>

  </base-layout>
</template>

<script>
import baseMixin from '@/mixins/base'
import util from '../../../utils/util'
import {countProfit} from '@/api/countapi'
import {findAllUpShopInfo} from '@/api/utilsapi'
import moment from 'moment';

export default {
  name: 'CountProfit',
  mixins: [
    baseMixin({
      idName: 'id',
      findData:countProfit,
      format(res) {
        return res.map(data => {
          return data
        })
      }
    })
  ],
  data() {
    return {
      pageShow: true,
      dialogData:{},
      users:[],
      tableColumnAttributes: [
        { name: '利润', value: 'profit'},
      ],
      filters: {
        facevalue: '',
        useruuid:'',
        busuuid:'',
        provinceuuid:'',
        starttime:new Date(),
        endtime:new Date()
      }
    }
  },
  methods: {
    async search(form){
      let para = {
        start: 0,
        pageSize: 10,
        facevalue: this.filters.facevalue,
        useruuid:this.filters.useruuid == "0" ? "": this.filters.useruuid, //JSON.parse(sessionStorage.getItem("user")).useruuid,
        busuuid:this.filters.busuuid == "0" ? "" : this.filters.busuuid,
        provinceuuid:this.filters.provinceuuid == "0" ? "" : this.filters.provinceuuid,
        starttime: this.filters.starttime == "" ? "" : moment(this.filters.starttime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD'),
        endtime: this.filters.endtime == "" ? "" : moment(this.filters.endtime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD')
      };
      this.searchOptions = para;
      this.setTableData()
    },
    async findAllUpShopInfo(){
      let para = {
        test:''
      };
      const result = await findAllUpShopInfo(para);
      if(result.data){
        this.users = result.data;
      }
    },
  },
  mounted() {
    this.findAllUpShopInfo();
  }
}
</script>
